package io.acna.qiniu.core;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by wscl on 2015/6/7.
 */
public class DirUtils {
    static List<String> fs = new ArrayList<String>();

    public static void main(String[] args) {

        listFile("F:" + File.separator + "test");
        for (String s : fs) {
            System.out.println(s);
        }
    }

    public static List<String> listFile(String file) {
        LinkedList<String> folderList = new LinkedList<String>(Arrays.asList(file));
        while (folderList.size() > 0) {
            File[] files = new File((String) folderList.poll()).listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory())
                    folderList.add(files[i].getPath());
                else {
                    Pattern p = Pattern.compile("\\.(jpg|mp4)");
                    Matcher m = p.matcher(files[i].getAbsolutePath());
                    while (m.find()) {
                        String fileName = files[i].getAbsolutePath();
                        fs.add(fileName);
                    }
                }
            }
        }
        return fs;
    }
}
